package application;

import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;

public class Note {
	
	public String Name;
	public String Content;
	public String Link;
	public Note(String name, String content, String link) {
		super();
		Name = name;
		Content = content;
		Link = link;
	}
	public Note() {
		super();
		this.Name = "new note";
		this.Content = "type here";
		this.Link = null;
	}
	
	public void dbCreateNote (String dbFile){
		ObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded
		        .newConfiguration(), dbFile);
		
		try{

	        		db.store(this);


		}
		finally{
			db.close();
		}
	}
	
	public void dbEditNote (String dbFile, Note c){
		ObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded
		        .newConfiguration(), dbFile);
		
		try{
			try{
				ObjectSet<Note> result = db
		        .queryByExample(Note.this);
				Note found = (Note) result.next();
				db.delete(found);
				this.setContent(c.getContent());
				this.setLink(c.getLink());
				this.setName(c.getName());
				db.store(this);
				
			}
			catch(IllegalStateException e){
				
			}

		}
		finally{
			db.close();
		}
	}
	
	public void dbDeleteNote (String dbFile){
		ObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded
		        .newConfiguration(), dbFile);
		
		try{
			try{
				ObjectSet<Note> result = db
		        .queryByExample(Note.this);
				Note found = (Note) result.next();
				db.delete(found);
			}
			catch(IllegalStateException e){
				
			}

		}
		finally{
			db.close();
		}
	}
	
	public String toString() {
		return Name;
	}
	public String getName() {
		return Name;
	}
	public String getContent() {
		return Content;
	}
	public String getLink() {
		return Link;
	}
	public void setName(String name) {
		Name = name;
	}
	public void setContent(String content) {
		Content = content;
	}
	public void setLink(String link) {
		Link = link;
	}
	
	
	
	

}
